package com.java1234.controller;

import com.java1234.entity.*;
import com.java1234.service.JixiaokaoheService;
import com.java1234.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 绩效考核 前端控制器
 * </p>
 *
 * @author zhai
 * @since 2025-05-09
 */
@RestController
@RequestMapping("/sys/jixiaokaohe")
public class JixiaokaoheController {

    @Autowired(required = false)
    private JixiaokaoheService service;

    @PostMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        String query = pageBean.getQuery() != null ? pageBean.getQuery().trim() : "";
        String query2 = pageBean.getQuery2() != null ? pageBean.getQuery2().trim() : "";
        if (StringUtil.isEmpty(query2)) {

        }
        List<PerformanceEvaluation> pageResult = service.getPerformanceEvaluationsByDateRange(query2,query2, query);
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("list",pageResult);
        resultMap.put("total",pageResult.size());
        return R.ok(resultMap);
    }


    @GetMapping("/months")
    public R getAvailableMonths() {
        // 1. 从数据库查询所有有绩效记录的月份
        List<String> months = service.getAvailableMonths();
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("data",months);
        return R.ok(resultMap);
    }

    // 部门横向对比
    @PostMapping("/departments/trend")
    public R horizontalComparison(@RequestBody PageBean pageBean) {
        String query = pageBean.getQuery() != null ? pageBean.getQuery().trim() : "";
        String query2 = pageBean.getQuery2() != null ? pageBean.getQuery2().trim() : "";
        List<DeptPerformanceDTO> result = service.getDeptPerformanceAnalysis("2025-04","2025-05");
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("list",result);
        return R.ok(resultMap);
    }

}
